package com.aaa.controller.mht;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.mht.TestPlanMht;
import com.aaa.service.mht.TestPlanMhtService;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 心理健康MHT计划表(TestPlanMht)表控制层
 *
 * @author makejava
 * @since 2022-09-01 08:03:08
 */
@RestController
@RequestMapping("testPlanMht")
public class TestPlanMhtController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanMhtService testPlanMhtService;

    /**
     * @param : null
     * @return :  
     * @create by: Username 刘亦辰 
     * @description: 查询计划   +  模糊查询 
     * @create time: 2022/9/1 8:18
     */

    @RequestMapping(value = "queryAllMhtPlan.do")
    public Result queryAllMhtPlan(PageSortEntity pageSortEntity, TestPlanMht testPlanMht) {
        List<TestPlanMht> testPlanMhtList = testPlanMhtService.queryAllMhtPlan(testPlanMht, pageSortEntity);
        Page page = (Page) testPlanMhtList;
        return success(page.getResult(), page.getTotal());
    }


    /**
     * 新增数据
     *
     * @param testPlanMht 实体
     * @return 新增结果
     */
    @RequestMapping(value = "saveTestPlanMht.do")
    public Result save(TestPlanMht testPlanMht) {
        TestPlanMht save = testPlanMhtService.save(testPlanMht);
        if (ObjectUtil.isNotEmpty(save)) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 编辑数据
     *
     * @param testPlanMht 实体
     * @return 编辑结果
     */
    @RequestMapping(value = "updateTestPlanMht.do")
    public Result update(TestPlanMht testPlanMht) {
        Integer update = testPlanMhtService.update(testPlanMht);
        if (update > 0) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 删除计划
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @RequestMapping(value = "delTestPlanMht.do")
    public Result deleteById(Integer id) {
        Boolean i = testPlanMhtService.deleteById(id);
        if (i) {
            return success();
        } else {
            return fail();
        }
    }

    /**
     * 批量删除计划
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @RequestMapping(value = "delTestPlanBatch.do")
    public Result deleteBatch(int[] id) {
        Integer integer = testPlanMhtService.delTestPlanBatch(id);
        if (integer > 0) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * @param
     * @return :  
     * @create by: Username 刘亦辰 
     * @description: 计划名 重复性校验 
     * @create time: 2022/9/1 16:35
     */
    @RequestMapping(value = "repetitionName.do", method = RequestMethod.GET)
    public Result repetitionName(TestPlanMht testPlanMht) {
        Integer integer = testPlanMhtService.repetitionName(testPlanMht);
        if (integer == 0) {
            return success("计划名称可用");
        }
        return fail("计划名称重复，不可用");
    }
}

